﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WJDHApp.Common;

namespace WJDHApp
{
    public partial class GVForm : Form
    {
        MyHttpUtil http = new MyHttpUtil();

        public GVForm()
        {
            InitializeComponent();
        }

        private void GVForm_Load(object sender, EventArgs e)
        {
            txtUrlJK.Text = "http://gvcn.gameview.asia/AddToCart.aspx?id=7";
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            string jk_url = txtUrlJK.Text;

            //HttpResult Result = http.HttpRes(jk_url);

            CookieContainer cc = new CookieContainer();
            cc.Add(new System.Uri("http://gvcn.gameview.asia"), new Cookie("CurrentUser", "M4qi2tPcUhCWtVyDOiBHGQ=="));
            cc.Add(new System.Uri("http://gvcn.gameview.asia"), new Cookie("CurrentLanguage", "cn"));
            cc.Add(new System.Uri("http://gvcn.gameview.asia"), new Cookie("CurrentCurrency", "RM"));

            var html = HttpHelper.SendDataByGET(jk_url, "", cc);


            if (html.Contains("http://www.w3.org"))
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);//加载文章页面
                //HtmlNode nodeArt = doc.DocumentNode.SelectSingleNode("//div[@class='hl_content']");
                //HtmlNode titleNode = nodeArt.SelectSingleNode("//div[@class='hl_c_title']/h2").FirstChild;

                HtmlNode cartNode = doc.GetElementbyId("availability_value");
                var cartStr = cartNode.InnerHtml;
                if (cartStr.Contains("商品缺货"))
                {
                    rtbContent.AppendText("商品缺货");
                }
            }


        }
    }
}
